﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BUS;
using System.Data;
using System.Data.SqlClient;
using DTO;

namespace RapChieuPhim
{
    public partial class QuanLyRapPhim : Form
    {

        #region #Quan li lich chieu THUONG

        LichChieuBUS lcbus = new LichChieuBUS();
        public QuanLyRapPhim()
        {
            InitializeComponent();
        }

        private void btnDatVe_Click(object sender, EventArgs e)
        {
            DatVe frmDatVe = new DatVe();
            frmDatVe.ShowDialog();
        }

        private void btnPhim_Click(object sender, EventArgs e)
        {
            PhimChieu frm = new PhimChieu();
            frm.Show();
        }

        public void LayDanhSachLichChieu()
        {
            dtgLichChieu.DataSource = lcbus.LayDanhSachLichChieu();
        }

        //private void QuanLyRapPhim_Load(object sender, EventArgs e)
        //{

        //}

        private void tabQLLC_Click(object sender, EventArgs e)
        {
            LayDanhSachLichChieu();
            cbxCaChieu.DataSource = lcbus.LayDanhSachMaCaChieu();
            cbxCaChieu.ValueMember = "MaCaChieu";
            cbxCaChieu.DisplayMember = "TenCaChieu";

        }

        private void btnTimKiem_Click(object sender, EventArgs e)
        {
            string tuKhoa = txtKhoa.Text.ToString();
            dtgLichChieu.DataSource = lcbus.LayDanhSachTimKiem(tuKhoa);
        }
        #endregion
        
        //Xu li quan li nhan vien Huynh
        #region #Quan li nhan vien HUYNH
        NhanVienBUS nvBUS = new NhanVienBUS();

        //Load du lieu len datagridview
        private void btnLoadDuLieu_Click(object sender, EventArgs e)
        {

            dtgnhanvien.DataSource = nvBUS.LoadDSNhanVien();
            //Load du lieu len comboxlop
           // DataTable dt = new DataTable();
           // dt = nvBUS.LoadDSNhanVien();
            cbxManv.DataSource = nvBUS.LoadDSNhanVien();
            cbxManv.DisplayMember = "HoTen";
            cbxManv.ValueMember = "Mã NV";
            Binding();
        }

        private void Binding()
        {
            cbxManv. DataBindings.Clear();
            cbxManv.DataBindings.Add("Text", dtgnhanvien.DataSource, "Mã NV");

            txtHoTen.DataBindings.Clear();
            txtHoTen.DataBindings.Add("Text", dtgnhanvien.DataSource, "Họ tên");

            dtpNgaySinh.DataBindings.Clear();
            dtpNgaySinh.DataBindings.Add("Text", dtgnhanvien.DataSource, "Ngày sinh");

            txtCMND.DataBindings.Clear();
            txtCMND.DataBindings.Add("Text", dtgnhanvien.DataSource, "CMND");

            cbxGioiTinh.DataBindings.Clear();
            cbxGioiTinh.DataBindings.Add("Text", dtgnhanvien.DataSource, "Giới tính");

            txtDiaChi.DataBindings.Clear();
            txtDiaChi.DataBindings.Add("Text", dtgnhanvien.DataSource, "Địa chỉ");

            txtMaChucVu.DataBindings.Clear();
            txtMaChucVu.DataBindings.Add("Text", dtgnhanvien.DataSource, "Mã cv");

            txtMaTinhTrang.DataBindings.Clear();
            txtMaTinhTrang.DataBindings.Add("Text", dtgnhanvien.DataSource, "Mã tình trạng");
        }

      
        private void btnThem_Click(object sender, EventArgs e)
        {
            string manv = cbxManv.Text;
            string hoTen = txtHoTen.Text;
            DateTime ngaysinh = dtpNgaySinh.Value;
            string cmnd = txtCMND.Text;
            string gioitinh = cbxGioiTinh.Text;
            string diachi = txtDiaChi.Text;
            string machucvu = txtMaChucVu.Text;
            int matinhtrang = int.Parse(txtMaTinhTrang.Text);
            
            nvBUS.ThemNhanVien(manv, hoTen, ngaysinh, cmnd, gioitinh, diachi, machucvu, matinhtrang);
            DataTable dt = new DataTable();
            dt = LoadDSNhanVien();
            MessageBox.Show("Thanh cong");
        }


        private DataTable LoadDSNhanVien()
        {
            DataTable dt = new DataTable();
            dt = nvBUS.LoadDSNhanVien();
            return dt;
        }

        private void btnSua_Click(object sender, EventArgs e)
        {
            string manv = cbxManv.Text;
            string hoTen = txtHoTen.Text;
            DateTime ngaysinh = dtpNgaySinh.Value;
            string cmnd = txtCMND.Text;
            string gioitinh = cbxGioiTinh.Text;
            string diachi = txtDiaChi.Text;
            string machucvu = txtMaChucVu.Text;
            int matinhtrang = int.Parse(txtMaTinhTrang.Text);

            nvBUS.SuaNhanVien(manv, hoTen, ngaysinh, cmnd, gioitinh, diachi, machucvu, matinhtrang);
            DataTable dt = new DataTable();
            dt = LoadDSNhanVien();
            MessageBox.Show("Thanh cong");
        }

        // Kieu tim kiem
        int kieutk = 0;
        private void btnTimKiemnv_Click(object sender, EventArgs e)
        {
            string tk = txtTuKhoanv.Text;
            switch (kieutk)
            {
                case 1:
                    dtgnhanvien.DataSource = nvBUS.TimTheoTenNV(tk);
                    break;
                case 2:
                    dtgnhanvien.DataSource = nvBUS.TimTheoMaNV(tk);
                    break;
                case 3:
                    dtgnhanvien.DataSource = nvBUS.TimTheoDiaChiNV(tk);
                    break;
                default:
                    dtgnhanvien.DataSource = nvBUS.TimTheoMaChucVuNV(tk);
                    break;
            }
            //dtgnhanvien.DataSource = nvBUS.TimTheoMaNV(tk);
            DataTable dt = new DataTable();
            dt = LoadDSNhanVien();
        }

        private void rbtennv_CheckedChanged(object sender, EventArgs e)
        {
            if (rbtennv.Checked == true)
                kieutk = 1;
        }

        private void rbmanv_CheckedChanged(object sender, EventArgs e)
        {
            if (rbmanv.Checked == true)
                kieutk = 2;
        }

        private void rbdiachi_CheckedChanged(object sender, EventArgs e)
        {
            if (rbdiachi.Checked == true)
                kieutk = 3;
        }

        private void rbchucvu_CheckedChanged(object sender, EventArgs e)
        {
            if (rbchucvu.Checked == true)
                kieutk = 4;
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Bạn thật sự muốn xóa nhân viên này ?", "Thông báo", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning) == DialogResult.Yes)
            {
                string manv = cbxManv.Text;
                nvBUS.XoaMotNV(manv);
                MessageBox.Show("Xóa thành công");
                DataTable dt = new DataTable();
                dt = LoadDSNhanVien();
            }
            
        }
        #endregion

        //Xu li chuc vu Huynh
        #region #Quan li chuc vu
        ChucVuBUS cvBUS = new ChucVuBUS();
        private void btnLoadDSCV_Click(object sender, EventArgs e)
        {
            dtgdsChucVu.DataSource = cvBUS.LoadDSChucVu();
            //Load du lieu len comboxlop
            DataTable dt = new DataTable();
            dt = cvBUS.LoadDSChucVu();
            cbxChucVu.DataSource = dt;
            cbxChucVu.DisplayMember = "TenChucVu";
            cbxChucVu.ValueMember = "MaChucVu";
            Binding1();
        }

        private void Binding1()
        {
            cbxChucVu.DataBindings.Clear();
            cbxChucVu.DataBindings.Add("Text", dtgdsChucVu.DataSource, "MaChucVu");

            txtTenChuVu.DataBindings.Clear();
            txtTenChuVu.DataBindings.Add("Text", dtgdsChucVu.DataSource, "TenChucVu");
        }
        #endregion

    }
}
